<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	
	public function init() {
		
		$view = new Zend_View ( $this->getOptions () );
		$view->headTitle ( 'ss' )->setSeparator ( ' - ' )->append ( 'My Site' );
		$view->headLink ()->appendStylesheet ( '/template/default/css/styles.css' );
		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper ( 'ViewRenderer' );
		$viewRenderer->setView ( $view );
		return $view;
	}
	protected function _initAutoload() {
		// Add autoloader empty namespace
		$autoLoader = Zend_Loader_Autoloader::getInstance ();
		$autoLoader->registerNamespace ( 'Smsgrid_' );
		return $autoLoader;
	}
	protected function _initRegistry() {
		$config = new Zend_Config_Ini ( CONFIG_PATH, APPLICATION_ENV );
		Zend_Registry::set ( 'config', $config );
	}
	
	protected function _initTemplatePath() {
		$front = Zend_Controller_Front::getInstance ();
		
		$front->setControllerDirectory ( array ('default' => APPLICATION_PATH . '/controllers', 'parent' => APPLICATION_PATH . '/parent/controllers' ) );
		$front->addControllerDirectory ( APPLICATION_PATH . '/parent/controllers', 'parent' );
	
		//		$front->run(APPLICATION_PATH.'/controllers');
	}
	
	protected function _initStylesheet() {
		$templatepath = DS . Zend_Registry::get ( 'config' )->resources->layout->templatePath . DS . Zend_Registry::get ( 'config' )->resources->layout->templateName;
		$cssPath = $templatepath . DS . Zend_Registry::get ( 'config' )->resources->layout->template->css;
		$view = new Zend_View ( $this->getOptions () );
		// retreives the css file names in and object array
		$styles = Zend_Registry::get ( 'config' )->resources->layout->template->styles;
		
		// converts the object array to and array
		$stylesArray = $styles->toArray ();
		
		foreach ( $stylesArray as $styleSheet ) :
			$view->headLink ()->appendStylesheet ( $cssPath . DS . $styleSheet );
		endforeach
		;
		
		return $view;
	}
	protected function _initResources() {
		$config = Zend_Registry::get ( 'config' );
		Zend_Registry::set ( 'resources', $config->resources );
	}
	protected function _initDb() {
		$resources = Zend_Registry::get ( 'resources' );
		
		$this->db = Zend_Db::factory ( $resources->db->adapter, $resources->db->params->toArray () );
		Zend_Db_Table::setDefaultAdapter ( $this->db );
		
		Zend_Registry::set ( 'db', $this->db );
	
	}
	protected function _initJavascripts() {
		$templatepath = DS . Zend_Registry::get ( 'config' )->resources->layout->templatePath . DS . Zend_Registry::get ( 'config' )->resources->layout->templateName;
		$jsPath = $templatepath . DS . Zend_Registry::get ( 'config' )->resources->layout->template->js;
		$view = new Zend_View ( $this->getOptions () );
		// retreives the javascript file names in and object array
		$javascripts = Zend_Registry::get ( 'config' )->resources->layout->template->javascripts;
		
		// converts the object array to and array
		$javascriptsArray = $javascripts->toArray ();
		
		foreach ( $javascripts as $jsFile ) :
			$view->headScript ()->appendFile ( $jsPath . DS . $jsFile );
		endforeach
		;
		
		return $view;
	}

}
